package tests
{
	import com.as3undohistory.manage.IUndoHistoryManager;
	import com.as3undohistory.manage.UndoHistoryManager;
	import com.as3undohistory.register.IObjectRegistration;
	import com.as3undohistory.register.ObjectRegistration;
	
	import flexunit.framework.TestCase;
	
	import tests.testclasses.UndoAbleTestClass;

	public class UndoHistoryManagerTest extends TestCase
	{
		public function UndoHistoryManagerTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testAddObject():void
		{
			var objReg:IObjectRegistration = new ObjectRegistration();
			var hm:IUndoHistoryManager = new UndoHistoryManager(objReg);
			
			var t:UndoAbleTestClass = new UndoAbleTestClass();
			
			hm.addObject(t);
		}
		
		public function testRemoveObject():void
		{
		}
		
		public function testUndo():void
		{
			var objReg:IObjectRegistration = new ObjectRegistration();
			var hm:IUndoHistoryManager = new UndoHistoryManager(objReg);
			
			var t:UndoAbleTestClass = new UndoAbleTestClass();
			var t2:UndoAbleTestClass = new UndoAbleTestClass();
			
			t.testStringProperty = "test1";
			t2.testStringProperty = "test2";
			
			hm.addObject(t);
			hm.addObject(t2);
			
			t.testStringProperty = "test3";
			t2.testStringProperty = "test4";
			
			hm.undo();
			
			assertEquals("test2",t2.testStringProperty);
			
			hm.undo();
			
			assertEquals("test1",t.testStringProperty);
			
		}
		
		public function testTransaction():void
		{
			var objReg:IObjectRegistration = new ObjectRegistration();
			var hm:IUndoHistoryManager = new UndoHistoryManager(objReg);
			
			var t:UndoAbleTestClass = new UndoAbleTestClass();
			
			t.testStringProperty = "test1";
			
			hm.addObject(t);
			hm.startTransaction();
			
			t.testStringProperty = "test2";
			t.testStringProperty = "test3";
			t.testStringProperty = "test4";
			t.testStringProperty = "test5";
			
			hm.endTransaction();
			
			hm.undo();
			
			assertEquals("test1",t.testStringProperty);
		}
		
	}
}